package demo01;


import java.net.InetAddress;
import java.net.UnknownHostException;

//测试ip
public class TestInetAddress {

    public static void main(String[] args) {
        try {
            //查询本机地址
            InetAddress net1 = InetAddress.getByName("127.0.0.1");
            InetAddress net2 = InetAddress.getByName("localhost");
            InetAddress net3 = InetAddress.getLocalHost();
            //查询网址ip地址
//            InetAddress net4 = InetAddress.getByName("www.baidu.com");
            InetAddress net4 = InetAddress.getByName("http://gitee.com/lihuaqi3336");

            System.out.println(net1);
            System.out.println(net2);
            System.out.println(net3);
            System.out.println(net4);
            System.out.println("========================");
            //常用方法
            System.out.println(net4.getAddress());
            System.out.println(net4.getHostAddress());
            System.out.println(net4.getCanonicalHostName());//获取它规范的名字ip
            System.out.println(net4.getHostName());


        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

    }
}
